home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.igs.net!usenet
- From: bnear@blvl.igs.net (Brian Near)
- Newsgroups: comp.lang.rexx
- Subject: Re: b tree search needed
- Date: Sun, 31 Mar 1996 21:01:02 -0500
- Organization: IGS - Information Gateway Services
- Distribution: world
- Message-ID: <ejzXxgabrEwS090yn@blvl.igs.net>
- References: <bgbxxgabrgbm090yn@blvl.igs.net> <4jj9nt$ssc@stratus.skypoint.net>
- <4jk56j$23f2@usenetw1.news.prodigy.com>
- NNTP-Posting-Host: bnear.blvl.igs.net
-
- In article <4jk56j$23f2@usenetw1.news.prodigy.com>,
- JXHQ58A@prodigy.com (Mark Lauritsen) wrote:
- >I don't know the details of the problem, but you can use stemmed
- >variables to get REXX to do such a search for you. I'll give you an
- >example and hopefully you can adapt it to your situation.
- >
- >Suppose you have a list of "records" containing a key and some data. For
- >example, the key could be a person's name and the data could be
- >address/phone/etc. Now suppose the records are numbered 1 to N. Given a
- >name, you want to find the corresponding record (or its number).
- >
- >number_from_key. = 0
- >
- >At this point, the value of number_from_key.anything is 0. Now, code the
- >following loop:
- >
- >do i = 1 to N /* N is the total number of records. */
- > temp = key.i
- > number_from_key.temp = i /* It's ok for temp to contain letters and
- >blanks*/
- >end
- >
- >Now, given a key value, you can do something like this:
- >
- >rec_num = number_from_key.key_val /* Looks up rec num given key val. */
- >if rec_num = 0 say "No entry for" key_val
- >else say "Data for" key_val "is" data.rec_num
- >
- >I guarantee REXX can do the lookup internally much faster than you can by
- >writting a binary search in REXX. Internally, REXX is probably using a
- >binary search, but it's written in C or some other compiled language.
- >
- >What do you think?
-
- That's essentially what I was doing previously. But while the search once
- the stem is loaded is admittedly fast, the wait to do this can be
- unacceptable.
- With the help from several folks here, I now have a way to determine the
- size of the file (and the records it holds). I now have a method to read
- records randomly, and I have a small, fast b-tree search.
- FWIW, the binary search is (IMHO), the preferred method. A file of 500,000
- records can be searched in approx 19 iterations max.
-
- -------------------------------
- bnear@blvl.igs.net
- casrsdfd@ibmmail.com
- -------------------------------
-